﻿<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>微信设置</h4>
		<div class="bk10"></div>
		<form class="form-horizontal" id="myform">
			<div class="form-group">
				<label for="appid" class="col-sm-2 control-label">公众号名称：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="name" style="width:240px;display:inline-block" value="<{$wechat['name']}>" placeholder="公众号名称">
				</div>
			</div>
			
			<div class="form-group">
				<label for="appsecret" class="col-sm-2 control-label"><span class='red'>*</span>微信号：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="account"  style="width:240px;display:inline-block" value="<{$wechat['account']}>" placeholder="appsecret">
				</div>
			</div>
			
			<div class="form-group">
				<label for="mchid" class="col-sm-2 control-label"><span class='red'>*</span>微信原始ID：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="original" style="width:240px;display:inline-block" value="<{$wechat['original']}>" placeholder="微信原始ID">
				</div>
			</div>
			
			<div class="form-group">
				<label for="partnerkey" class="col-sm-2 control-label">消息加解密方式</label>
				<div class="col-sm-5">
					<label for="encrypt_mode_0">
						<input type="radio" name="encrypt_mode"  value="0" id="encrypt_mode_0" <empty name="wechat['encrypt_mode']">checked="checked" </empty>/>
						明文模式
					</label>
					<label for="encrypt_mode_1">
						<input type="radio" name="encrypt_mode"  value="1" id="encrypt_mode_1" <eq name="wechat['encrypt_mode']" value="1">checked="checked" </eq>/>
						兼容模式
					</label>
					<label for="encrypt_mode_2">
						<input type="radio" name="encrypt_mode"  value="2" id="encrypt_mode_2" <eq name="wechat['encrypt_mode']" value="2">checked="checked" </eq>/>
						安全模式
					</label>
				</div>
			</div>
			
			<div class="form-group">
				<label for="mchid" class="col-sm-2 control-label"><span class='red'>*</span>EncodingAESKey：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="encodingaeskey" style="width:240px;display:inline-block" value="<{$wechat['encodingaeskey']}>"  placeholder='请填写EncodingAESKey'>
				</div>
			</div>
			
			<div class="form-group">
				<label for="mchid" class="col-sm-2 control-label"><span class='red'>*</span>通讯地址：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" readonly=true  style="width:240px;display:inline-block" value="http://<{$Think.server.http_host}>/api.php">
				</div>
			</div>
			
			<div class="form-group">
				<label for="mchid" class="col-sm-2 control-label"><span class='red'>*</span>通讯Token：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" readonly=true name="wetoken"  value="<{$wechat['token']}>" style="width:240px;display:inline-block" >
					<input type="button" onclick="tokenGen();" value="重新生成" class="btn btn-default" />
				</div>
			</div>
			
			<div class="form-group">
				<label for="mchid" class="col-sm-2 control-label"><span class='red'>*</span>AppId：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="key" style="width:240px;display:inline-block" value="<{$wechat['appid']}>" placeholder='微信开发者凭据'>
				</div>
			</div>
			
			<div class="form-group">
				<label for="mchid" class="col-sm-2 control-label"><span class='red'>*</span>AppSecret：</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="secret" style="width:240px;display:inline-block" value="<{$wechat['appsecret']}>"  placeholder='微信开发者凭据'>
				</div>
			</div>
			
			
			
			
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-default col-sm-2">保存</button>
				</div>
			</div>
		</form>
	</div>
	<!-- mainCon// -->
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/validate/messages_zh.js"></script>
<script>
$(function(){
	$("#myform").validate({
		rules : {
			name:{
				required: true,
			},
			account:{
				required:true,
			},
			original:{
				required:true,
			},
			encodingaeskey:{
				required:true,
			},
			wetoken:{
				required:true,
			},
			key:{
				required:true,
			},
			secret:{
				required:true,
			}
			
		},
		messages : {

		},
		submitHandler : function(form){
			var ajaxUrl = "<{:U('Admin/Wechats/Setting')}>";
			 $.post(ajaxUrl,$(form).serialize(),function(r){
    			if(r.error == 1){
    				layer.alert(r.errmsg,{icon: 2});
    			}else{
    				layer.alert(r.errmsg,{icon: 1},function(){
    					window.location.reload();
    				});
    			}
    			return false;
    		});
        	return false
		}
	});
});


function tokenGen() {
	var letters = 'abcdefghijklmnopqrstuvwxyz0123456789';
	var token = '';
	for(var i = 0; i < 32; i++) {
		var j = parseInt(Math.random() * (31 + 1));
		token += letters[j];
	}
	$(':text[name="wetoken"]').val(token);
}
</script>

<include file="Public/footer" /> 